import * as resume from '@/api/resume.js'
import * as index from '@/api/index.js'
export default {
	name: 'Intention',


	data() {
		return {
			placeholder:'',
			form: {
				areas_index: -1,
				drving_id: 0,
				drving_name: '',
				age_index: -1
			},
			addForm: {
				position_ids: '', //服务技能id
				positionName: '', //服务技能名称
				type: 0, //兼职全职
				areas_id: 0, //地区
				phone: '', //手机号
				txt: '', //自我描述
				salary_name: '', //期望薪资
				salary_max: 0, //最大钱
				salary_min: 0, //最小钱
				age_id: '', //经验要求
				age_text: '', //经验要求
			},
			areas_arr: [],
			age_arr:[], //获取经验
			typeIndex: '0',
			phone: '', //电话
			IntentionType: [{
					name: '个人',
					value: 1
				},
				{
					name: '团队',
					value: 2
				}
			],
			salary_arr: [
				[],
				[]
			],
			salary_index: [
				[0],
				[0]
			],
			salary_min: 0,
			salary_max: 0,
			salary: '',
			txt: '',
			idlist: []
		}
	},
	onShow() {
	},
	onLoad() {
		this.getNc()
		this.getMemberResumeInfo()
		this.getAgeList()
		this.getAreasList()
		uni.$on('name',(data)=>{
			let arr = []
			let arrID = []
			data.forEach(item=>{
				arr.push(item.title)
				arrID.push(item.id)
			})
			this.addForm.type_text = arr
			this.addForm.type_ids = arrID.join(',')
		})
	},
	onLaunch() {

	},
	methods: {
		getNc() {
			index.nameGetConfig({name:'re_tis'}).then(res=>{
				this.placeholder = res.data.re_tis
			})
		},
		//获取数据
		getMemberResumeInfo() {
			resume.getMemberResumeInfo().then(res => {
				this.addForm = res.data
				this.addForm.edit = 'qzyx'
				this.addForm.areas_pid = '1'
			})
		},
		//经验要求选择
		agePickerChange(e) {
			this.addForm.age_id = this.age_arr[e.detail.value].id
			this.addForm.age_text = this.age_arr[e.detail.value].title
		},
		nameclick() {
		},
		//期望薪资
		getSalarysList() {
			let that = this
			resume.getSalarysList().then(res => {
				this.salary_arr = [res.data, []]
			})
		},
		//获取经验
		getAgeList() {
			index.getAgeList().then(res => {
				this.age_arr = res.data
			})
		},
		//常驻地区
		getAreasList() {
			index.getAreasList({
				pid: 1
			}).then(res => {
				this.areas_arr = res.data
			})
		},
		checkIndex(item, index) {
			this.typeIndex = index
			this.addForm.type = item.value
		},
		Pickerareas(e) {
			this.form.areas_index = e.detail.value
			this.addForm.drving_id = this.areas_arr[e.detail.value].id;
			this.addForm.areas_text = this.areas_arr[e.detail.value]['title'];
			this.addForm.areas_id = this.areas_arr[e.detail.value].id;
		},
		PickerSalary(e) {
			this.salary_index = e.detail.value
			if (this.salary_arr[0][e.detail.value[0]]['id'] == 0) {
				this.salary_min = this.salary_arr[0][e.detail.value[0]]['id'];
				this.salary_max = 0;
				this.addForm.salary_max = 0;
				this.addForm.salary_min = this.salary_arr[0][e.detail.value[0]]['id'];
			} else {
				this.salary_min = this.salary_arr[0][e.detail.value[0]]['id'];
				this.salary_max = this.salary_arr[1][e.detail.value[1]]['id'];
				this.addForm.salary_max = this.salary_arr[1][e.detail.value[1]]['id'];
				this.addForm.salary_min = this.salary_arr[0][e.detail.value[0]]['id'];
			}
			if (e.detail.value[0] == 0) {
				this.addForm.salary = '面议';
			} else {
				this.addForm.salary = this.salary_arr[0][e.detail.value[0]].num + '-' + this.salary_arr[1][e.detail
					.value[1]
				].value;
				this.addForm.salary_max = this.salary_arr[1][e.detail.value[1]]['id'];
				this.addForm.salary_min = this.salary_arr[0][e.detail.value[0]]['id'];
			}
		},
		MultiColumnChange(e) {
			if (e.detail.column == 0) {
				if (this.salary_arr[0][e.detail.value].item) {
					this.toArr(JSON.parse(this.salary_arr[0][e.detail.value].item))
				} else {
					this.$set(this.salary_arr, 1, [])
				}
			} else {}

		},
		//转成数组
		toArr(obj) {
			var arr = []
			for (let i in obj) {
				let o = {};
				o[i] = obj[i];
				arr.push(o[i])
			}
			this.salary_arr = [this.salary_arr[0], arr]
		},
		//服务技能跳转
		jumpclassification(){
			this.$tools.navigate('/pages/resume/classification/index')
		},
		//确定
		ok_form() {
			console.log(this.addForm,'提交数据')
			if (this.addForm.phone == '') {
				var that = this.phone_null = true;
				this.$tools.toast('请填写联系方式');
				return;
			}
			if (this.addForm.position_ids == '') {
				this.position_null = true;
				this.$tools.toast('请选择服务技能');
				return;
			}
			if (this.addForm.salary == '') {
				this.salary_null = true;
				this.$tools.toast('请选择期望薪资');
				return;
			}
			if (this.addForm.areas_id == 0) {
				this.areas_null = true;
				this.$tools.toast('请选择常驻地区');
				return;
			}
			if (this.addForm.txt == 0) {
				// this.areas_null = true;
				this.$tools.toast('请输入自我描述');
				return;
			}
			if(this.addForm.salary_max < this.addForm.salary_min) {
				this.$tools.toast('重新选择薪资');
				return;
			}
			resume.editMemberResume(this.addForm).then(res => {
				this.$tools.succend('保存成功!')
				setTimeout(res=>{
					uni.navigateBack({
						data: 1
					})
				},500)
			})
		}
	}
}
